﻿//fastclick
Origami.fastclick(document.body);
$(function () {
    var deviceWidth = $('body').width();
    $('body').css('padding-bottom', $('footer').height());

    $('.item-info2').css('background-position-x', deviceWidth - parseInt($('.item-info2').css('background-size')) - 18).find('.title2').css('width', deviceWidth - 30 - $('.item-icon2').width() - 10);

    $('#db-content').css('padding-bottom', $('footer').height());

    $('.submit').on('click', function () {
        $.modal({
            type: 'confirm',
            title: '领取奖品',
            section: '<p>领取奖品后，可以在“兑换记录”中查看详情。</p>',
            callback: {
                save: function () {
                    window.loading = $.modal({
                        type: 'loading',
                        title: '正在处理，请稍后···'
                    });

                    $.ajax({
                        url: options.pickupPrizeUrl,
                        type: 'POST',
                        timeout: 5000,
                        dataType: 'json',
                        //data: { orderId: 0 },
                        success: function (response) {
                            if (response.status == 1) {
                                window.location.href = options.orderDetailUrl;
                            } else {
                                window.loading.close();
                                $.modal({
                                    type: 'alert',
                                    title: response.msg ? response.msg : '领取失败',
                                    callback: {
                                        save: function () {
                                            if (response.status == -1) {
                                                window.location.href = options.custAddressUrl;
                                            } else if (response.status == -2) {
                                                window.location.href = options.orderDetailUrl;

                                            } else {
                                                window.location.reload();
                                            }
                                        }
                                    }
                                });
                            }
                        },
                        error: function (e) {
                            ajaxError(e);
                        }
                    });
                }
            }
        })
    });

});
function ajaxError(e) {
    loading.close();

    if (e.status == 0) {
        $.modal({
            type: 'alert',
            title: '网络连接失败，请检查网络',
        });
    } else if (e.status == 404) {
        $.modal({
            type: 'alert',
            title: '找不到服务器地址，请重试',
        });
    } else {
        $.modal({
            type: 'alert',
            title: '系统发生错误，请重试',
        });
    }
}